import tensorflow as tf

mnist = tf.keras.datasets.fashion_mnist
(x_train,y_train),(x_test,y_test) = mnist.load_data()
x_train,x_test=x_train/255.0,x_test/255.0 # 归一化数据，变小输入特征更适合神经网络吸收

model = tf.keras.models.Sequential([
    tf.keras.layers.Flatten(), # 拉直为一维数组
    tf.keras.layers.Dense(128, activation='relu'), # 第一层网络128个神经元，用rulu函数
    tf.keras.layers.Dense(10, activation='softmax') # 第二层网络10个神经元
])

model.compile(optimizer='adam',
              loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=False),
              metrics=['sparse_categorical_accuracy'])

model.fit(x_train,y_train,batch_size=32,epochs=5,validation_data=(x_test,y_test),validation_freq=1)

model.summary()